package com.ai.test2.service;

import com.ai.test2.client.ConsumerClient;
import com.ai.test2.dao.ProviderMapper;
import com.ai.test2.model.Provider;
import org.bytesoft.compensable.Compensable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Date:  2018/11/5
 * Time:  13:42
 * Email: siy@hmgsoft.com
 * Created by siy
 */
@Service("providerService")
@Compensable(
		interfaceClass = ProviderService.class,
		confirmableKey = "providerServiceConfirm",
		cancellableKey = "providerServiceCancel"
)
public class ProviderServiceImpl implements ProviderService {

	@Resource
	private ProviderMapper providerMapper;
	@Resource
	private ConsumerClient consumerClient;

	@Override
	@Transactional
	public void increaseAmount(String id, int amount) {
		Provider provider = providerMapper.selectByPrimaryKey(id);
		provider.setTCount(provider.getTCount()-amount);
		providerMapper.updateByPrimaryKeySelective(provider);
		consumerClient.update();

	}
}
